var t = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../utils/util")), a = getApp();

Page({
    data: {
        usClass: !0,
        goodsId: null,
        storeName: "",
        longitude: "",
        latitude: "",
        timer: "",
        storeListByGoods: [],
        reply: [],
        isLoadMore: !0,
        page: 1,
        totalPage: 0,
        total: 0
    },
    onLoad: function(t) {
        var a, o, e;
        "" === (null !== (a = t.goodsId) && void 0 !== a ? a : "") && "" === (null !== (o = t.longitude) && void 0 !== o ? o : "") && "" === (null !== (e = t.latitude) && void 0 !== e ? e : "") || (this.setData({
            goodsId: parseInt(t.goodsId),
            storeName: "",
            longitude: t.longitude,
            latitude: t.latitude
        }), this.getStoreListByGoods());
    },
    getStoreListByGoods: function() {
        var t = this, o = a.getNetAddresss("plugin.coupon-store.frontend.store.getStoreListByGoods"), e = {
            goods_id: this.data.goodsId,
            store_name: this.data.storeName,
            longitude: this.data.longitude,
            latitude: this.data.latitude
        };
        a._postNetWork({
            url: o,
            data: e,
            success: function(a) {
                var o = a.data;
                wx.hideLoading(), wx.hideNavigationBarLoading(), wx.stopPullDownRefresh(), 1 == o.result ? (t.data.totalPage = o.data.last_page, 
                t.data.totalPage || (t.data.totalPage = 0), t.setData({
                    storeListByGoods: o.data.data,
                    total: o.data.total
                })) : (t.data.page = t.data.page - 1, t.isLoadMore = !1, wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 1500
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    searchChange: function(a) {
        var o = this, e = a.detail;
        this.setData({
            storeName: e,
            page: 1,
            isLoadMore: !0
        }), this.timer && clearTimeout(this.timer), this.timer = setTimeout(function() {
            t.default.debounce(o.getStoreListByGoods());
        }, 500);
    },
    getMoreData: function() {
        var t = this;
        if (this.data.isLoadMore = !1, !(this.data.page >= this.data.totalPage)) {
            this.data.page = this.data.page + 1;
            var o = a.getNetAddresss("plugin.coupon-store.frontend.store.getStoreListByGoods"), e = {
                goods_id: this.data.goodsId,
                store_name: this.data.storeName,
                longitude: this.data.longitude,
                latitude: this.data.latitude,
                page: this.data.page
            };
            a._getNetWork({
                url: o,
                data: e,
                success: function(a) {
                    var o = a.data, e = o.data.data;
                    1 == o.result ? (t.data.isLoadMore = !0, t.setData({
                        storeListByGoods: t.data.storeListByGoods.concat(e)
                    })) : (t.data.page = t.data.page - 1, t.isLoadMore = !1, wx.showToast({
                        icon: "none",
                        title: o.msg,
                        duration: 1500
                    }));
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        wx.showNavigationBarLoading(), wx.showLoading({
            title: "刷新中..."
        }), this.setData({
            page: 1,
            storeName: ""
        }), this.getStoreListByGoods();
    },
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多了");
    },
    onShareAppMessage: function() {}
});